package LeetCode.LeetCode2;

/**
 * 最大子数组和
 * @author lumin
 * @date 2022/03/22 22:38
 **/
public class Num53 {
    public static int maxSubArray(int[] nums) {
        int max = -10001;
        int mid = -10001;
        int i = 0;
        while(i < nums.length){
            mid += nums[i];
            mid = Math.max(mid,nums[i]);
            max = Math.max(mid,max);
            i++;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = {-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(maxSubArray(nums));
    }
}